package com.yh.homestay.controller;

import com.yh.homestay.pojo.CapitalGoods;
import com.yh.homestay.service.EchartsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @ClassName EchartsController
 * @Description 统计Controller
 * @Date 2020/1/13 15:49
 */
@Controller
@Api(description = "统计管理")
@RequestMapping(value = "/echarts")
public class EchartsController {

    @Autowired
    private EchartsService echartsService;

    /**
     * @param
     * @Date: 2020/1/13 15:49
     * @Description: 查找商品操作信息（添加、删除、修改）传给前台
     * @return: java.util.List
     */
    @RequestMapping(value = "/items",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "商品操作信息统计", notes = "查找商品操作信息（添加、删除、修改）")
    public List findItemAction() {
        Map<String, Integer> map = echartsService.echartsShowsItems();
        List<Map<String, Object>> list = new ArrayList<>();
        for (String in : map.keySet()) {
            Map<String, Object> guan = new HashMap<>();
            guan.put("name", in);
            guan.put("value", map.get(in));
            list.add(guan);
        }
        return list;
    }

    /**
     * @param
     * @Date: 2020/1/13 15:50
     * @Description: 物资统计
     * @return: java.util.List<com.yh.homestay.pojo.CapitalGoods>
     */
    @RequestMapping(value = "/goods",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "物资统计", notes = "统计物资信息")
    public List<CapitalGoods> capitalGoodsShow() {
        List<CapitalGoods> users = echartsService.echartsShowsGoods();
        return users;
    }

}
